home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 138
/
Volume 138 Aug 19 2011 - Damaged.iso
/
Games
/
hopes_babysitting_maze.swf
/
scripts
/
__Packages
/
Classes
/
bsmEnemy.as
next >
Wrap
Text File
|
2011-08-19
|
3KB
|
107 lines
class Classes.bsmEnemy extends Classes.bsmEntity
{
var IGNORE_TIMER = 5;
var SPRAY_TIMER = 4;
var SOUNDTIMER_MAX = 1;
function bsmEnemy(t_data, t_levelPath)
{
super();
this.assetID = t_data.assetID;
this.speed = t_data.speed;
this.levelPath = t_levelPath;
this.soundTimer = 0;
this.currentPoint = this.levelPath.findPoint(t_data.startPoint);
this.previousPoint = this.currentPoint;
this.type = t_data.type;
this.currentFacing = "up";
this.setToPoint();
this.targetPoint = {x:this.x,y:this.y};
}
function setToPoint()
{
var t_point = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
this.x = t_point._x;
this.y = t_point._y;
}
function update(t_elapsed)
{
this.xMove = 0;
this.yMove = 0;
var _loc10_ = undefined;
if(this.soundTimer > 0)
{
this.soundTimer -= t_elapsed;
}
var _loc9_ = false;
var _loc2_ = undefined;
var _loc3_ = undefined;
var _loc4_ = undefined;
var _loc6_ = undefined;
var _loc7_ = this.speed * t_elapsed;
_loc2_ = this.targetPoint.x - this.x;
_loc3_ = this.targetPoint.y - this.y;
if(Math.abs(_loc2_) < 1 && Math.abs(_loc3_) < 1)
{
this.x = this.targetPoint.x;
this.y = this.targetPoint.y;
this.findNextPoint();
this.update(t_elapsed);
return undefined;
}
var _loc5_ = "up";
if(_loc2_ >= 1)
{
_loc5_ = "right";
}
else if(_loc2_ <= -1)
{
_loc5_ = "left";
}
else if(_loc3_ >= 1)
{
_loc5_ = "down";
}
this.currentFacing = _loc5_;
this.mc.gotoAndStop(this.currentFacing);
_loc6_ = Math.sqrt(_loc2_ * _loc2_ | _loc3_ * _loc3_);
if(_loc6_ != 0)
{
_loc4_ = _loc7_ / _loc6_;
if(_loc4_ > 1)
{
_loc4_ = 1;
}
if(this.x != this.targetPoint.x)
{
this.xMove = _loc2_ * _loc4_;
}
if(this.y != this.targetPoint.y)
{
this.yMove = _loc3_ * _loc4_;
}
}
}
function turnAround()
{
this.currentPoint = this.previousPoint;
var t_mc = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
this.targetPoint = {x:t_mc._x,y:t_mc._y};
}
function hitReact()
{
if(this.soundTimer <= 0)
{
this.levelPath.engine.playSound("puppy");
this.levelPath.engine.loseScore();
}
this.soundTimer = this.SOUNDTIMER_MAX;
}
function findNextPoint()
{
this.previousPoint = this.currentPoint;
this.currentPoint = this.levelPath.findAdjacentPoint(this.currentPoint);
var t_mc = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
this.targetPoint = {x:t_mc._x,y:t_mc._y};
}
}